//
//  MovieDetailCollectionViewController.m
//  豆瓣YHY
//
//  Created by dllo on 15/11/1.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieDetailCollectionViewController.h"
#import "MovieDetailCollectionViewCell.h"
#import "AppTools.h"
@interface MovieDetailCollectionViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,retain)NSMutableArray *myarray;
@end

@implementation MovieDetailCollectionViewController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Register cell classes
    
    [AppTools getLocalDataWithURL:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/movielist.php" andBlock:^(id dic) {
        NSMutableDictionary *dica = dic;
        NSMutableArray *array = [dica objectForKey:@"result"];
        for (NSMutableDictionary *dicresult in array) {
            self.moviea = [[Movie alloc]init];
            [self.moviea setValuesForKeysWithDictionary:dicresult];
            [self.myarray addObject:self.moviea];
        }
        [self.collectionView reloadData];
    }];
    NSLog(@"%@",self.myarray);
    
    
    
    
    [self.collectionView registerClass:[MovieDetailCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    self.collectionView.delegate = self;//UITableView、==UICollectionView协议
    self.collectionView.dataSource = self;
    //把collectionView添加到View上
    [self.view addSubview:self.collectionView];
    
    self.view.backgroundColor = [UIColor yellowColor];
    //创建流水布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(250, 250);//每个格子的大小
    CGFloat paddingY = 20;
    CGFloat paddingX = 40;
    layout.minimumLineSpacing = paddingY;//每行之间的距离
    layout.sectionInset = UIEdgeInsetsMake(paddingY, paddingX, paddingY, paddingX);
     UICollectionViewController *centroller = [[UICollectionViewController alloc]initWithCollectionViewLayout:layout];//设置展示布局
    
    self.collectionView.backgroundColor = [UIColor yellowColor];
    // Do any additional setup after loading the view.
}


//- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//    return 2;
//    
//}
//- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//    static NSString *cell1 = @"cell";
//    UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cell1 forIndexPath:indexPath];
//    
//}
//








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete implementation, return the number of sections
    return 0;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of items
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    // Configure the cell
    
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
